package com.ext.aic.ui;

import android.os.Bundle;

import com.ext.aic.handler.AppUpdateHandler;
import com.ext.aic.handler.FormValidatorHandler;
import com.ext.aic.utils.RTEditUtils;
import com.mobsandgeeks.saripaar.ValidationError;
import com.mobsandgeeks.saripaar.Validator;

import java.util.List;

public class BaseActivity extends BasePureActivity implements Validator.ValidationListener {

    protected FormValidatorHandler validatorHandler = new FormValidatorHandler();
    private Bundle savedInstanceState;
    private AppUpdateHandler appUpdateHandler = new AppUpdateHandler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        authorizationHandler.tokenRenewal();
        authorizationHandler.refreshTokenRenewal(this, this);
        RTEditUtils.getInstance().initForActivity(this, savedInstanceState);
        validatorHandler.bindFormValidator(this);

        appUpdateHandler.checkUpdate(this, false);
    }

    @Override
    protected void onResume() {
        super.onResume();
        RTEditUtils.getInstance().initForActivity(this, savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RTEditUtils.getInstance().destroy();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        RTEditUtils.getInstance().onSaveInstanceState(outState);
    }

    @Override
    public void onValidationSucceeded() {

    }

    @Override
    public void onValidationFailed(List<ValidationError> errors) {
        validatorHandler.onValidationFailed(errors, this);
    }
}
